package fem2.material.cohesive_law;

import inf.jlinalg.IMatrix;
import inf.jlinalg.IVector;

import java.util.HashMap;
import java.util.Map;

import fem2.Element;
import fem2.ElementManager;
import fem2.StrategyPart;
import fem2.Variable;

/**
 * abstract class for all cohesive law in strong discontinuity modelling
 * 
 * @author hbui
 * 
 */
public abstract class CohesiveLaw extends ElementManager implements StrategyPart {

	protected double Gf; // fracture energy
	protected double ft; // tensile strength

	private Map<Element, Variable> elementVariable = new HashMap<Element, Variable>();

	public CohesiveLaw(double Gf, double ft) {
		this.Gf = Gf;
		this.ft = ft;
	}

	/**
	 * 
	 * @return the tensile strength of material
	 */
	public double getTensileStrength() {
		return ft;
	}

	/**
	 * 
	 * @return fracture energy of material
	 */
	public double getFractureEnergy() {
		return Gf;
	}

	/**
	 * compute traction on jump surface<br>
	 * T = [tn tm]
	 * 
	 * @param e
	 * @param w
	 *            displacement jump = [wn wm]
	 * @return
	 */
	public abstract IVector computeJumpTraction(Element e, IVector w);

	/**
	 * compute sitffness on jump surface<br>
	 * Ct = [d(tn)/d(wn) d(tn)/d(wm) ; <br>
	 * d(tm)/d(wn) d(tm)/d(wm)]
	 * 
	 * @param e
	 * @param w
	 *            displacement jump = [wn wm]
	 * @return
	 */
	public abstract IMatrix computeJumpStiffness(Element e, IVector w);

	/**
	 * set the variable for element
	 * 
	 * @param e
	 * @param v
	 */
	public void setVariable(Element e, Variable v) {
		elementVariable.put(e, v);
	}

	/**
	 * get the variable associated with the element
	 * 
	 * @param e
	 * @return
	 */
	public Variable getVariable(Element e) {
		return elementVariable.get(e);
	}

	@Override
	public void Initialize(Element e) {
	}

	@Override
	public void InitializeSolutionStep(Element e) {
	}

	@Override
	public void InitalizeNonlinearIteration(Element e) {
	}

	@Override
	public void FinalizeNonlinearIteration(Element e) {
	}

	@Override
	public void FinalizeSolutionStep(Element e) {
	}

	@Override
	public void CalculateOutputData(Element e) {
	}

}
